package aishua.com.mytestapplist.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;


public class PreferProcesserUtils {

	private static PreferProcesserUtils preferProcesser = new PreferProcesserUtils();;

	private SharedPreferences sharedPreferences;


	public static PreferProcesserUtils getInstant() {
//		if (null == preferProcesser) {
//			
//		}
		return preferProcesser;
	}

	public boolean saveStrPreference(Context context, String fileName,
									 String paramName, String paramValue) {
		sharedPreferences = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putString(paramName, paramValue);

		return editor.commit();
	}


	public boolean saveBoolPreference(Context context, String fileName,
									  String paramName, boolean paramValue) {
		sharedPreferences = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean(paramName, paramValue);
		return editor.commit();
	}
	
	public boolean saveLongPreference(Context context, String fileName,
									  String paramName, long paramValue) {
		sharedPreferences = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putLong(paramName, paramValue);
		return editor.commit();
	}
	
	public boolean saveIntPreference(Context context, String fileName,
									 String paramName, int paramValue) {
		sharedPreferences = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putInt(paramName, paramValue);
		return editor.commit();
	}

	public boolean setShowGuidePage(Context context, String fileName,
									String paramName, boolean paramValue){
		sharedPreferences = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		Editor editor = sharedPreferences.edit();
		editor.putBoolean(paramName, paramValue);
		return editor.commit();
	}
	
	
	public String getStrPreferenceByParamName(Context context, String fileName,
											  String paramName) {
		sharedPreferences = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		return sharedPreferences.getString(paramName, "");
	}

	public boolean getBoolPreferenceByParamName(Context context,
												String fileName, String paramName) {
		sharedPreferences = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean(paramName, false);
	}
	
	public Long getLongPreferenceByParamName(Context context,
											 String fileName, String paramName) {
		sharedPreferences = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		return sharedPreferences.getLong(paramName, -1);
	}
	
	public int getIntPreferenceByParamName(Context context,
										   String fileName, String paramName) {
		sharedPreferences = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		return sharedPreferences.getInt(paramName, -1);
	}
	
	public boolean isShowGuidePage(Context context, String fileName, String paramName){
		sharedPreferences = context.getSharedPreferences(fileName,
				Context.MODE_PRIVATE);
		if(sharedPreferences==null){
			return true;
		}
		return sharedPreferences.getBoolean(paramName, false);
	}
	
}
